import dicom
def orderDICOMFiles(dir=None,suffix="", verbose = False):
    try:
        if( dir == None ):
            return []
        filelist = glob.glob(dir+"/*"+suffix)
        dicom_files = []
        pos = {}
        for file in filelist:
            dfile = dicom.read_file(file)
            if( verbose ): print "orderDICOMFiles: %s"%file
            if( not os.path.isdir(file ) ):
                try:
                    if( verbose ):
                        print "orderDICOMFiles: InstanceNumber %s"%\
                            dfile.data_element('InstanceNumber').value
                    pos[dfile.data_element('InstanceNumber').value] = file
                except IOError:
                    print "not a dicom file",file
        return pos
    except Exception, error:
        print "Failed in orderDICOMFiles", error
        return {} 